package com.receiver;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;

import com.activity.OnePixelActivity;
import com.ruggear.rtc.MainActivity;

public class OnePixelReceiver extends BroadcastReceiver
{
    @Override
    public void onReceive(Context context, Intent intent)
    {
        // https://www.jianshu.com/p/20e3dfc7f23c Intent.ACTION_USER_PRESENT
        if (intent.getAction().equals(Intent.ACTION_SCREEN_OFF ) || intent.getAction().equals(Intent.ACTION_USER_PRESENT) )
        {
            //屏幕关闭启动1像素Activity
            Log.w("myInfo","屏幕关闭");
            Intent intent1 = new Intent(context, OnePixelActivity.class);
            intent1.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);//FLAG_ACTIVITY_NEW_TASK FLAG_ACTIVITY_SINGLE_TOP FLAG_ACTIVITY_REORDER_TO_FRONT
            context.startActivity(intent1);
        } else if (intent.getAction().equals(Intent.ACTION_SCREEN_ON)) {
            //屏幕打开 结束1像素
            Log.w("myInfo","屏幕打开");
            context.sendBroadcast(new Intent("finish"));
            /*Intent main = new Intent(Intent.ACTION_MAIN);
            main.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);//FLAG_ACTIVITY_CLEAR_TOP
            main.addCategory(Intent.CATEGORY_HOME);
            context.startActivity(main);*/

//            Intent mainIntent = new Intent(context, MainActivity.class);
//            mainIntent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);//FLAG_ACTIVITY_CLEAR_TOP FLAG_ACTIVITY_SINGLE_TOP
//            //main.addCategory(Intent.CATEGORY_HOME);
//            context.startActivity(mainIntent);
        }
    }
}
